package com.twu.biblioteca;


public class Book {

    private String title, author;
    private boolean available;


    public Book(String title, String author) {
        this.title = title;
        this.author = author;
        this.available = true;
    }

    public String reserveBook() {
        if (this.available) {
            this.available = false;
            return ("Thank You! Enjoy the book.");


        } else {
            return ("Sorry this book is unavailable for reservation.");

        }
    }

    public String toString() {
        return title + " BY " + author;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Book book = (Book) o;

        if (available != book.available) return false;
        if (author != null ? !author.equals(book.author) : book.author != null) return false;
        if (title != null ? !title.equals(book.title) : book.title != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = title != null ? title.hashCode() : 0;
        result = 31 * result + (author != null ? author.hashCode() : 0);
        result = 31 * result + (available ? 1 : 0);
        return result;
    }
}
